import { takeEvery, put} from 'redux-saga/effects'
import { loadProducts, saveProducts } from '../actions/product.action'
import axios from 'axios'

function * handleLoadProducts () {
    // 向服务器发送请求
    const { data } = yield axios.get('http://localhost:3005/goods ')
    // 将商品列表数据保存到本地的 store 对象
    yield put(saveProducts(data))
}

export default function * productSaga() {
    // 加载商品列表数据
    yield takeEvery(loadProducts, handleLoadProducts)
}